from math import pow,sqrt

def OISER_ca_A1( ED_c, EF_a, BW_a, OSIR_a, EF_c, ABS_o, AT_ca, BW_c, ED_a, OSIR_c):
    return (((OSIR_c * ED_c * EF_c) / (BW_c) + (OSIR_a * ED_a * EF_a) / (BW_a)) * ABS_o) / (AT_ca) * pow(10,-6)

def OISER_nc_A2(ED_c, EF_c, BW_c, ABS_o, OSIR_c, AT_nc):
    return (OSIR_c * ED_c * EF_c * ABS_o) / (BW_c * AT_nc) * pow(10,-6)

def DCSER_ca_A3(SSAR_a, ED_c, SSAR_c, E_v, SAE_a, EF_c, EF_a, BW_a, AT_ca, BW_c, ED_a, ABS_d, SAE_c):
    return (SAE_c * SSAR_c * EF_c * ED_c * E_v * ABS_d) / (BW_c * AT_ca) * pow(10,-6) + (
                SAE_a * SSAR_a * EF_a * ED_a * E_v * ABS_d) / (BW_a * AT_ca) * pow(10,-6)

def SAE_c_A4( BW_c,SER_c, H_c):
    return 239 * pow(H_c,0.417)* pow(BW_c,0.517) * SER_c

def SAE_a_A5( SER_a, BW_a, H_a):
    return 239 * pow(H_a,0.417) * pow(BW_a,0.517) * SER_a


def DCSER_nc_A6( ED_c, SSAR_c, E_v, EF_c, BW_c, AT_nc, ABS_d, SAE_c):
    return (SAE_c * SSAR_c * EF_c * ED_c * E_v * ABS_d) / (BW_c * AT_nc) * pow(10,-6)


def PISER_ca_A7( fspo,ED_c, PIAF, BW_a, DAIR_a, PM_10, DAIR_c, fspi, AT_ca, EFI_a, BW_c, EFO_c, ED_a,
            EFO_a, EFI_c):
    return (PM_10 * DAIR_c * ED_c * PIAF * (fspo * EFO_c + fspi * EFI_c)) / (BW_c * AT_ca) * pow(10,-6) + (
            PM_10 * DAIR_a * ED_a * PIAF * (fspo * EFO_a + fspi * EFI_a)) / (BW_a * AT_ca) * pow(10,-6)

def PISER_nc_A8( fspo,  ED_c, PIAF, PM_10, DAIR_c, fspi, BW_c, EFO_c, AT_nc, EFI_c):
    return (PM_10 * DAIR_c * ED_c * PIAF * (fspo * EFO_c + fspi * EFI_c)) / (BW_c * AT_nc) * pow(10,-6)

def IOVER_cal_A9( ED_c, BW_a, DAIR_a, DAIR_c, AT_ca, BW_c, EFO_c, ED_a, EFO_a, VF_suroa):
    return VF_suroa * ((DAIR_c * EFO_c * ED_c) / (BW_c * AT_ca) + (DAIR_a * EFO_a * ED_a) / (BW_a * AT_ca))

def IOVER_nc1_A10( ED_c, DAIR_c, BW_c, EFO_c, AT_nc, VF_suroa):
    return VF_suroa * (DAIR_c * EFO_c * ED_c) / (BW_c * AT_nc)

def IOVER_ca2_A11( ED_c, BW_a, DAIR_a, DAIR_c, AT_ca, BW_c, EFO_c, ED_a, EFO_a, VF_suboa):
    return VF_suboa * ((DAIR_c * EFO_c * ED_c) / (BW_c * AT_ca) + (DAIR_a * EFO_a * ED_a) / (BW_a * AT_ca))

def IOVER_nc2_A12( ED_c, DAIR_c, BW_c, EFO_c, AT_nc, VF_suboa):
    return VF_suboa * (DAIR_c * EFO_c * ED_c) / (BW_c * AT_nc)

def IOVER_ca3_A13(VF_gwoa,  ED_c, BW_a, DAIR_a, DAIR_c, AT_ca, BW_c, EFO_c, ED_a, EFO_a):
    return VF_gwoa * ((DAIR_c * EFO_c * ED_c) / (BW_c * AT_ca) + (DAIR_a * EFO_a * ED_a) / (BW_a * AT_ca))

def IOVER_nc3_A14(ED_c, DAIR_c, VF_gwoa, BW_c, EFO_c, AT_nc):
    return VF_gwoa * (DAIR_c * EFO_c * ED_c) / (BW_c * AT_nc)

def IIVER_ca1_A15(VF_subia, ED_c, BW_a, DAIR_a, DAIR_c, AT_ca, BW_c, EFO_c, ED_a, EFO_a):
    return VF_subia * ((DAIR_c * EFO_c * ED_c) / (BW_c * AT_ca) + (DAIR_a * EFO_a * ED_a) / (BW_a * AT_ca))


def IIVER_ncl_A16(VF_subia, ED_c, DAIR_c, BW_c, AT_nc, EFI_c):
    return VF_subia * (DAIR_c * EFI_c * ED_c) / (BW_c * AT_nc)


def IIVER_ca2_A17(VF_gwia, ED_c, BW_a, DAIR_a, DAIR_c, EFI_a, AT_ca, BW_c, ED_a, EFI_c):
    return VF_gwia * ((DAIR_c * EFI_c * ED_c) / (BW_c * AT_ca) + (DAIR_a * EFI_a * ED_a) / (BW_a * AT_ca))


def IIVER_nc2_A18(VF_gwia, ED_c, DAIR_c, BW_c, AT_nc, EFI_c):
    return VF_gwia * (DAIR_c * EFI_c * ED_c) / (BW_c * AT_nc)


def CGWER_ca_A19(ED_c, EF_a, BW_a, EF_c, AT_ca, GWCR_c, BW_c, ED_a, GWCR_a):
    return (GWCR_c * EF_c * ED_c) / (BW_c * AT_ca) + (GWCR_a * EF_a * ED_a) / (BW_a * AT_ca)


def CGWER_nc_A20(ED_c, EF_c, GWCR_c, AT_nc, BW_c):
    return (GWCR_c * EF_c * ED_c) / (BW_c * AT_nc)


def OISER_ca_A21(EF_a, BW_a, AT_ca, OSIRa, ED_a, ABS_o):
    return (OSIRa * ED_a * EF_a * ABS_o) / (BW_a * AT_ca) * pow(10,-6)


def OISER_nc_A22(EF_a, BW_a, OSIRa, ED_a, ABS_o, AT_nc):
    return (OSIRa * ED_a * EF_a * ABS_o) / (BW_a * AT_nc) * pow(10,-6)


def DCSER_ca_A23(SSAR_a, EF_a, E_v, BW_a, AT_ca, ED_a, ABS_d, SAE_a):
    return (SAE_a * SSAR_a * EF_a * ED_a * E_v * ABS_d) / (BW_a * AT_ca) * pow(10,-6)


def DCSER_nc_A24(SSAR_a, EF_a, E_v, BW_a, ED_a, AT_nc, ABS_d, SAE_a):
    return (SAE_a * SSAR_a * EF_a * ED_a * E_v * ABS_d) / (BW_a * AT_nc) * pow(10,-6)


def PISER_ca_A25(BW_a, PIAF,fspo, DAIR_a, PM_10, fspi, EFI_a, AT_ca, ED_a, EFO_a):
    return (PM_10 * DAIR_a * ED_a * PIAF * (fspo * EFO_a + fspi * EFI_a ))/ (BW_a * AT_ca) * pow(10,-6)


def PISER_nc_A26(fspo, PIAF, BW_a, DAIR_a, PM_10, fspi, EFI_a, ED_a, AT_nc, EFO_a):
    return (PM_10 * DAIR_a * ED_a * PIAF * (fspo * EFO_a + fspi * EFI_a)) / (BW_a * AT_nc) * pow(10,-6)


def IOVER_cal_A27( BW_a, DAIR_a, VF_suroa, AT_ca, ED_a, EFO_a):
    return VF_suroa * (DAIR_a * EFO_a * ED_a) / (BW_a * AT_ca)


def IOVER_nc1_A28(BW_a, DAIR_a, VF_suroa, ED_a, AT_nc, EFO_a):
    return VF_suroa * (DAIR_a * EFO_a * ED_a) / (BW_a * AT_nc)


def IOVER_ca2_A29(BW_a, DAIR_a, VF_suboa, AT_ca, ED_a, EFO_a):
    return VF_suboa * (DAIR_a * EFO_a * ED_a) / (BW_a * AT_ca)


def IOVER_nc2_A30(BW_a, DAIR_a, VF_suboa, ED_a, AT_nc, EFO_a):
    return VF_suboa * (DAIR_a * EFO_a * ED_a) / (BW_a * AT_nc)


def IOVER_ca3_A31(BW_a, DAIR_a, AT_ca, VF_gwoa, ED_a, EFO_a):
    return VF_gwoa * (DAIR_a * EFO_a * ED_a) / (BW_a * AT_ca)


def IOVER_nc3_A32(BW_a, DAIR_a, VF_gwoa, ED_a, AT_nc, EFO_a):
    return VF_gwoa * (DAIR_a * EFO_a * ED_a) / (BW_a * AT_nc)


def IIVER_cal_A33(VF_subia, BW_a, DAIR_a, EFI_a, AT_ca, ED_a):
    return VF_subia * (DAIR_a * EFI_a * ED_a) / (BW_a * AT_ca)


def IIVER_ncl_A34(VF_subia, BW_a, DAIR_a, EFI_a, ED_a, AT_nc):
    return VF_subia * (DAIR_a * EFI_a * ED_a) / (BW_a * AT_nc)


def IIVER_ca2_A35(VF_gwia, BW_a, DAIR_a, EFI_a, AT_ca, ED_a):
    return VF_gwia * (DAIR_a * EFI_a * ED_a) / (BW_a * AT_ca)


def IIVER_nc2_A36(VF_gwia, BW_a, DAIR_a, EFI_a, ED_a, AT_nc):
    return VF_gwia * (DAIR_a * EFI_a * ED_a) / (BW_a * AT_nc)


def CGWER_ca_A37(AT_ca, EF_a, BW_a, ED_a, GWCR_a):
    return (GWCR_a * EF_a * ED_a) / (BW_a * AT_ca)



def CGWER_nc_A38(EF_a, BW_a, AT_nc, ED_a, GWCR_a):
    return (GWCR_a * EF_a * ED_a) / (BW_a * AT_nc)


def SF_i_B1(IUR, BW_a, DAIR_a):
    return (IUR * BW_a) / (DAIR_a)


def RfD_i_B2(RfC, BW_a, DAIR_a):
    return (RfC * DAIR_a) / (BW_a)


def SF_d_B3(ABS_gi, SF_o):
    return (SF_o) / (ABS_gi)


def RfD_d_B4(ABS_gi, RfD_o):
    return RfD_o * ABS_gi


def CR_ois_C1(C_sur, OISER_ca, SF_o):
    return OISER_ca * C_sur * SF_o


def CR_dcs_C2(C_sur, OISER_ca, SF_d):
    return OISER_ca * C_sur * SF_d


def CR_pis_C3(C_sur, PISER_ca, SF_i):
    return PISER_ca * C_sur * SF_i


def CR_iov1_C4(IOVER_ca1, C_sur, SF_i):
    return IOVER_ca1 * C_sur * SF_i


def CR_iov_C5(IOVER_ca2, C_sub, SF_i):
    return IOVER_ca2 * C_sub * SF_i


def CR_iiv1_C6(SF_i, IIVER_ca1, C_sub):
    return IIVER_ca1 * C_sub * SF_i


def CR_n_C7(CR_ois, CR_iov2, CR_iov1, CR_dcs, CR_pis, CR_iivl):
    return CR_ois + CR_dcs + CR_pis + CR_iov1 + CR_iov2 + CR_iivl


def HQ_ois_C8(SAF, OISER_nc, C_sur, RfD_o):
    return (OISER_nc * C_sur) / (RfD_o * SAF)


def HQ_dcs_C9(DCSER_nc, RfD_d, C_sur, SAF):
    return (DCSER_nc * C_sur) / (RfD_d * SAF)


def HQ_pis_C10(SAF, C_sur, RfD_i, PISER_nc):
    return (PISER_nc * C_sur) / (RfD_i * SAF)


def HQ_iov1_C11(SAF, C_sur, RfD_i, IOVER_nc1):
    return (IOVER_nc1 * C_sur) / (RfD_i * SAF)


def HQ_iov2_C12(IOVER_nc2, C_sub, RfD_i, SAF):
    return (IOVER_nc2 * C_sub) / (RfD_i * SAF)


def HQ_iiv1_C13(SAF, RfD_i, IIVER_nc1, C_sub):
    return (IIVER_nc1 * C_sub) / (RfD_i * SAF)


def HI_n_C14(HQ_pis, HQ_dcs, HQ_iov1, HQ_ivv, HQ_ois, HQ_iov):
    return HQ_ois + HQ_dcs + HQ_pis + HQ_iov1 + HQ_iov + HQ_ivv


def CR_iov3_C15(IOVER_ca3, C_gw, SF_i):
    return IOVER_ca3 * C_gw * SF_i


def CR_iv2_C16(IIVER_ca2, C_gw, SF_i):
    return IIVER_ca2 * C_gw * SF_i


def CR_cgw_C17(CGWER_ca, C_gw, SF_o):
    return CGWER_ca * C_gw * SF_o


def CR_n_C18(CR_iov3, CR_cgw, CR_iiv):
    return CR_iov3 + CR_iiv + CR_cgw


def HQ_iov3_C19(IOVER_nc3, C_gw, RfD_i, WAF):
    return (IOVER_nc3 * C_gw) / (RfD_i * WAF)


def HQ_iiv2_C20(IIVER_nc2, C_gw, RfD_i, WAF):
    return (IIVER_nc2 * C_gw) / (RfD_i * WAF)


def HQ_cgw_C21(WAF, RfD_o, C_gw, CGWER_nc):
    return (CGWER_nc * C_gw) / (RfD_o * WAF)


def HI_n_C22(HQ_cgw, HQ_iov, HQ_ivv):
    return HQ_iov +HQ_ivv+HQ_cgw

# 原公式输出的是百分比
def PCR_i_D1(CR_i, CR_n):
    return (CR_i) / (CR_n)

# 原公式输出的是百分比
def PHQ_i_D2(HQ_i, HI_n):
    return (HQ_i) / (HI_n)


def SR_D3(P_1, X_1, X_2, P_2):
    return ((X_2 - X_1) / X_1) / ((P_2 - P_1) / P_1)


def RCVS_ois_E1( ACR, OISER_ca, SF_o):
    return ACR / (OISER_ca * SF_o)


def RCVS_dcs_E2( ACR, DCSER_ca, SF_d):
    return ACR / (DCSER_ca * SF_d)


def RCVS_pis_E3( ACR, PISER_ca, SF_i):
    return ACR / (PISER_ca * SF_i)


def RCVS_iov1_E4( IOVER_ca1, ACR, SF_i):
    return ACR / (IOVER_ca1 * SF_i)


def RCVS_iov_E5( IOVER_ca2, ACR, SF_i):
    return ACR / (IOVER_ca2 * SF_i)


def RCVS_iiv_E6( IIVER_ca1, ACR, SF_i):
    return ACR / (IIVER_ca1 * SF_i)


def RCVS_n_E7( PISER_ca, SF_d, SF_i, OISER_ca, IOVER_ca1, DCSER_ca, SF_0, IVOER_ca2, IIVER_ca1, ACR):
    return ACR / (OISER_ca * SF_0 + DCSER_ca * SF_d + (PISER_ca + IOVER_ca1 + IVOER_ca2 + IIVER_ca1) * SF_i)


def HCVS_ois_E8( SAF, OISER_nc, AHQ, RfD_o):
    return (RfD_o * SAF * AHQ) / (OISER_nc)


def HCVS_dcs_E9( SAF, RfD_d, AHQ, DCSER_nc):
    return (RfD_d * SAF * AHQ) / (DCSER_nc)


def HCVS_pis_E10( SAF, RfD_i, AHQ, PISER_nc):
    return (RfD_i * SAF * AHQ) / (PISER_nc)


def HCVS_iov1_E11( SAF, RfD_i, AHQ, IOVER_nc1):
    return (RfD_i * SAF * AHQ) / (IOVER_nc1)


def HCVS_iov2_E12( SAF, IOVER_nc2, RfD_i, AHQ):
    return (RfD_i * SAF * AHQ) / (IOVER_nc2)


def HCVS_iiv_E13( SAF, IIVER_nc1, RfD_i, AHQ):
    return (RfD_i * SAF * AHQ) / (IIVER_nc1)


def HCVS_n_E14( IOVER_nc1, AHQ, DCSER_nc, RfD_i, RfD_o, SAF, PISER_nc, RfD_d, IOVER_nc2, IIVER_nc1, OISER_nc):
    return (AHQ * SAF) / (
                (OISER_nc) / (RfD_o) + (DCSER_nc) / (RfD_d) + (PISER_nc + IOVER_nc1 + IOVER_nc2 + IIVER_nc1) / (RfD_i))


def CVS_pgw_E15( MCL_gw, LF_sgw):
    return (MCL_gw) / (LF_sgw)


def RCVG_iov_E16( IOVER_ca3, ACR, SF_i):
    return ACR / (IOVER_ca3 * SF_i)


def RCVG_iiv_E17( IIVER_ca2, ACR, SF_i):
    return ACR / (IIVER_ca2 * SF_i)


def RCVG_cgw_E18( CGWER_ca, ACR, SF_o):
    return ACR / (CGWER_ca * SF_o)


def RCVG_n_E19( IIVER_ca2, CGWER_ca, SF_i, SF_o, IOVER_ca3, ACR):
    return ACR / ((IOVER_ca3 + IIVER_ca2) * SF_i + CGWER_ca * SF_o)


def HCVG_iov_E20( AHQ, IOVER_nc3, RfD_i, WAF):
    return (RfD_i * WAF * AHQ) / (IOVER_nc3)


def HCVG_iiv_E21( AHQ, IIVER_nc2, RfD_i, WAF):
    return (RfD_i * WAF * AHQ) / (IIVER_nc2)


def HCVG_cgw_E22( AHQ, WAF, CGWER_nc, RfD_o):
    return (RfD_o * WAF * AHQ) / (CGWER_nc)


def HCVG_n_E23( AHQ, IOVER_nc3, RfD_i, CGWER_nc, RfD_o, IIVER_nc2, WAF):
    return (AHQ * WAF) / ((IOVER_nc3 + IIVER_nc2) / (RfD_i) + (CGWER_nc) / (RfD_o))


def D_s_eff_F1( Theta_ws, D_w, H_, Theta, D_a, Theta_as):
    return D_a * (pow(Theta_as,3.33)) / pow(Theta,2) + D_w * pow(Theta_ws,3.33) / (pow(H_,2 )*pow(Theta,2 ))


def Theta_F2( Rho_b, Rho_s):
    return 1 - Rho_b / Rho_s


def Theta_ws_F3(Rho_w, Rho_ws, Rho_b):
    return (Rho_b * Rho_ws) / Rho_w


def Theta_as_F4(Theta, Theta_ws):
    return Theta - Theta_ws


def D_crackeff_F5( Theta_acrack, D_w, Theta_wcrack, H_ , D_a, ):
    return D_a * pow(Theta_acrack,3.33) / pow((Theta_acrack +Theta_wcrack),2) + D_w * pow(Theta_wcrack,3.33) / (
            H_* pow(Theta_acrack  + Theta_wcrack,2))


def D_cap_eff_F6( Theta_acap, D_w, H, Theta_wcap , D_a):
    return D_a * pow(Theta_acap,3.33) / (Theta_acap  +Theta_wcap) + D_w * (Theta_acap) / (
            H* pow( Theta_acap + Theta_wcap,2) )


def D_gws_eff_F7( h_v, h_cap, D_cap_eff, D_s_eff, L_gw):
    return L_gw / (h_cap / (D_cap_eff) + h_v / (D_s_eff))


def K_sw_F8(K_d, H, Theta_as, Rho_b, Theta_ws):
    return (Theta_ws + K_d * Rho_b + H* Theta_as)/Rho_b


def K_d_F9(K_oc, f_oc):
    return K_oc * f_oc


def f_oc_F10(f_om):
    return f_om / (1.7 * 1000)


def DF_oa_F11(U_air, Delta_air, W, A):
    return (U_air * W * Delta_air) / A


def DF_ia_F12(ER,L_B):
    return L_B * ER * 1 / 86400


def Q_s_F13( Pi, R_crack, Z_crack, Mu_air, K_v, X_crack, dP):
    return (2 * Pi * dP * K_v * X_crack) / (Mu_air  / R_crack  )

def R_crack_F14( A_b, X_crack, Eta):
    return (A_b * Eta) / X_crack


def VF_suroa1_F15(Pi, K_sw, DF_oa, H  ,Tau, D_s_eff, Rho_b, ):
    return (Rho_b / (DF_oa) *sqrt((4*D_s_eff*H)/(Pi*Tau*31536000*K_sw*Rho_b)))*pow(10,3)


def VF_suroa2_F16(DF_oa, Tau, d, Rho_b):
    return (d * Rho_b) / (DF_oa * Tau * 31536000) *pow(10,3)


def VF_suroa_F17(VF_suroa1,VF_suroa2):
    return min(VF_suroa1,VF_suroa2)


def VF_suboa1_F18(K_sw, DF_oa, H , L_s, D_s_eff):
    return (1/((1 + (DF_oa * L_s) / D_s_eff) * K_sw / H ))*pow(10,3)


def VF_suboa2_F19(d_sub, Tau, DF_oa, Rho_b):
    return (d_sub * Rho_b) / (DF_oa * Tau * 31536000) *pow(10,3)


def VF_suboa_F20(VF_suboa1, VF_suboa2):
    return min(VF_suboa1,VF_suboa2)

def VF_gwoa_F21(DF_oa, H ,L_gw, D_gws_eff):
    return 1 / ((1 + (DF_oa * L_gw) / (D_gws_eff)) * 1 / H )*pow(10,3)


def VF_subia1_F22(K_sw, H , L_s, L_crack, D_crack_eff, D_s_eff,Eta, DF_ia):
    return 1 / (K_sw / H *(1+(D_s_eff)/(DF_ia*L_s )+(D_s_eff*L_crack)/(D_crack_eff*L_s*Eta))*(DF_ia)/(D_s_eff )*L_s )*pow(10,3)


def VF_subia_F23(e ,Xi, K_sw, H , L_s, Q_s, A_b, D_s_eff,  DF_ia):

    return 1 / (K_sw / H *(pow(e,Xi)+(D_s_eff)/(DF_ia*L_s )+(D_s_eff*A_b)/(Q_s*L_s )*(pow(e,Xi))*(DF_ia*L_s)/(D_s_eff*pow(e,Xi) )))*pow(10,3)


def Xi_F24(D_crack_eff, L_crack, Q_s, A_b, Eta):
    return (Q_s * L_crack) / (A_b * D_crack_eff * Eta)


def VF_subia2_F25(d_sub, Tau, Rho_b, DF_ia):
    return (d_sub * Rho_b) / (DF_ia * Tau * 31536000) *pow(10,3)


def VF_subia_F26(VF_subia1, VF_subia2):
    return min(VF_subia1, VF_subia2)

def VF_gwia_F27(H , D_crack_eff, L_crack, Eta, L_gw, DF_ia,D_gws_eff):
    return 1 / (1 / H  *(1+(D_gws_eff)/(DF_ia*L_gw )+(D_crack_eff*L_crack)/(D_crack_eff*L_gw*Eta))*(DF_ia)/(D_gws_eff)*L_gw )*pow(10,3)


def VF_gwia_F28(e,Xi, D_gws_eff, H , Q_s, A_b,L_gw, DF_ia,):
    return 1 / (1 / H *(pow(e,Xi)+(D_gws_eff)/(DF_ia*L_gw )+(D_gws_eff*A_b)/(Q_s*L_gw )*(pow(e,Xi)-1))*(DF_ia*L_gw)/(D_gws_eff*pow(e,Xi) ))*pow(10,3)


def LF_sgw1_F29(gw, K_sw, LF_spw):
    return (LF_spw - gw) /K_sw

def LF_spw_gw_F30(I, U_gw, Delta_gw,W):
    return 1 / (1 + (U_gw * Delta_gw) / (I * W))


def LF_sgw2_F31(d_sub, I, Tau, Rho_b):
    return (d_sub * Rho_b) / (I * Tau)


def LF_sgw_F32(LF_sgw1, LF_sgw2):
    return min(LF_sgw1, LF_sgw2)
